#include <linux/module.h>

#include <linux/fs.h>
#include <linux/errno.h>
#include <linux/miscdevice.h>
#include <linux/kernel.h>
#include <linux/major.h>
#include <linux/mutex.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/stat.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/tty.h>
#include <linux/kmod.h>
#include <linux/gfp.h>


static int major = 0;
static struct class *hello_class;

static ssize_t hello_open(struct inode *inode, struct file *file)
{
	printk("open driver\n");
	return 0;
}

static ssize_t hello_close(struct inode *inode, struct file *file)
{
	printk("close driver\n");
	return 0;
}

struct file_operations hello_drv = {
	.owner	 = THIS_MODULE,
	.open	 = hello_open,
	.release = hello_close,
};

static int __init hello_init(void)
{
	int err;

	printk("init driver\n");

	major = register_chrdev(0, "hello", &hello_drv);

	
	hello_class = class_create(THIS_MODULE, "hello_class");
	err = PTR_ERR(hello_class);
	if (IS_ERR(hello_class)){
		unregister_chrdev(major,"hello");
		return -1;
	}

	device_create(hello_class, NULL, MKDEV(major, 0), NULL, "hello"); /*/dev/hello */

	return 0;
}

static void  __exit hello_exit(void)
{
	printk("exit driver\n");

	device_destroy(hello_class, MKDEV(major, 0));
	class_destroy(hello_class);
	unregister_chrdev(major,"hello");
	
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
